package org.lilred.nzbberry.models;

import java.util.Date;

import org.json.me.JSONArray;
import org.json.me.JSONObject;
import org.lilred.nzbberry.webservice.SabnzbdActionClient;

public class HistoryNzbModel {
	int index;
	String actionLine;
	String name;
	String id;
	String status;
	JSONArray log;
	String category;
	String errorMessage;
	String size;
	Date completionDate;
	
	public HistoryNzbModel(int index, JSONObject json) {
		this.index = index;
		try {
			actionLine = json.getString("action_line");
			name = json.getString("name");
			id = json.getString("nzo_id");
			status = json.getString("status");
			try { log = json.getJSONArray("stage_log");
			} catch (Exception e) { System.out.println(e.getMessage()); } //Log is null
			try { category = json.getString("category");
			} catch (Exception e) { System.out.println(e.getMessage()); } //Category is null
			errorMessage = json.getString("fail_message");
			size = json.getString("size");
			completionDate = new Date(json.getLong("completed") * 1000);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	public void delete() {
		SabnzbdActionClient deleteClient = new SabnzbdActionClient();
		deleteClient.deleteHistory(id);
	}
	
	public int getIndex() { return index; }
	public String getFilename() { return name; }
	public Date getCompletionDate() { return completionDate; }
	public String getStatus() { return status; }
	public String getErrorMessage() { return errorMessage; }
	public String getActionLine() { return actionLine; }
}
